/****************************************
*
*	EoSC_PlayerController
*	
*	This class allows the player to control their pawn.
*
*	ToDo:
*	Too much.
*
****************************************/

class EoSC_PlayerController extends UDKPlayerController;

var float 				PreDist;
var private float		viewRotationPitch; // Store View Pitch.


simulated event PostBeginPlay()
{
	super.PostBeginPlay();
}

// Starting the ShoulderCam Function
exec function ShoulderCam()
{
	if(EoSC_Camera(PlayerCamera).CameraStyle != 'FirstPerson')
	{
		`Log("Switching to Shoulder Camera");
		PreDist = PlayerCamera.FreeCamDistance;					// Storing our previous camera distance...
		EoSC_Camera(PlayerCamera).CameraStyle = 'ShoulderCam';	// Type casting our camera script to access the variable CameraStyle
		// Setting the GroundSpeed to 1/2 of the normal speed.
		Pawn.GroundSpeed /= 2;
		// Setting a wider FOV.
		DefaultFOV = 70;
	}
}

// End the ShoulderCam and going back to the normal Cam.
exec function ReturnCam()
{
	if(EoSC_Camera(PlayerCamera).CameraStyle == 'ShoulderCam')
	{
		`Log("Switching to Normal Cam");
		PlayerCamera.FreeCamDistance = PreDist;					// Restoring the previous camera distance
		EoSC_Camera(PlayerCamera).CameraStyle = 'ThirdPerson';	// Restoring the previous camera style
		// Set the GroundSpeed back to normal.
		Pawn.GroundSpeed *= 2;
		// Switching back to normal FOV.
		DefaultFOV = 90;
	}
}

function UpdateRotation( float DeltaTime )
{
	local Rotator	DeltaRot, newRotation, ViewRotation;

	ViewRotation = Rotation;
	if (Pawn != none)
	{
		Pawn.SetDesiredRotation(ViewRotation);
	}

	// Calculate Delta to be applied on ViewRotation
	DeltaRot.Yaw	= PlayerInput.aTurn;
	DeltaRot.Pitch	= PlayerInput.aLookUp;

	ProcessViewRotation( DeltaTime, ViewRotation, DeltaRot );
	SetRotation(ViewRotation);

	// Store adjusted pitch in our class variable so we can use it outside of the method.
	self.viewRotationPitch = ViewRotation.Pitch;

	ViewShake( deltaTime );

	NewRotation = ViewRotation;
	NewRotation.Roll = Rotation.Roll;
	
	// Change our pawn's direction only if we are currently moving, in first person, or in ShoulderCam mode
	if ( EoSC_Camera(PlayerCamera).CameraStyle == 'ShoulderCam' 
		|| EoSC_Camera(PlayerCamera).CameraStyle == 'FirstPerson' 
		||	( Pawn != None && ( PlayerInput.RawJoyRight != 0.0 || PlayerInput.RawJoyUp != 0.0 ) ) )  
	{
		Pawn.FaceRotation(NewRotation, deltatime);
	}
}

function Rotator GetAdjustedAimFor( Weapon W, vector StartFireLoc )
{
	local Rotator adjustedAimRotator;
	
	// Use our adjusted pitch along with our pawns orientation.
	adjustedAimRotator.Pitch = viewRotationPitch;
	adjustedAimRotator.Roll = Pawn.Rotation.Roll;
	adjustedAimRotator.Yaw = Pawn.Rotation.Yaw;
	
	return adjustedAimRotator;
}

function HideMesh(bool meshVisible) 
{
	Pawn.Mesh.SetOwnerNoSee(meshVisible);
}

defaultproperties
{
	// Setting the default name.
	Name="Default__EoSC_PlayerController"
	// Setting the default Camera class.
	CameraClass=class'EoSCelest.EoSC_Camera'
	// Setting the default FoV.
	DefaultFOV=90.f
}